﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GMS.BIZ;

namespace Web.Information
{
    public partial class WebForm7 : System.Web.UI.Page
    {
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            if (((Account)Session["Account"]).RoleCurrent.Equals('s')) Response.Redirect("Default.aspx");
            //拿Account中得currentRole
            Account myAccount = (Account)Session["Account"];
            Staff myStaff = new Staff();
            switch (myAccount.RoleCurrent)
            {
                case 'a': myStaff = (Admin)Session["Admin"]; break;
                case 'c': myStaff = (ClassTeacher)Session["ClassTeacher"]; break;
                case 't': myStaff = (Teacher)Session["Teacher"]; break;
                default: Response.Redirect("~/"); break;
            }
            //绑定DropDownList
            if (!IsPostBack)
            {
                DropDownList_gender.Items.Add("男");
                DropDownList_gender.Items.Add("女");
            }
            Staff myTeacher = myStaff;
            Label_tchid.Text = myTeacher.TeacherId;
            TextBox_tchname.Text = myTeacher.TeacherName;
            if (myTeacher.TeacherGender.Trim() == "男")
                DropDownList_gender.SelectedIndex = 0;
            else
                DropDownList_gender.SelectedIndex = 1;
            TextBox_tchoffice.Text = myTeacher.TeacherOffice;
            TextBox_tchofficetel.Text = myTeacher.TeacherOfficeTel;
            TextBox_tchmobile.Text = myTeacher.TeacherMobile;
            TextBox_tchmail.Text = myTeacher.TeacherMail;
            TextBox_tchaward.Text = myTeacher.TeacherAward;
            TextBox_tchfield.Text = myTeacher.TeacherField;
            TextBox_tchtitle.Text = myTeacher.TeacherTitle;
            if (myTeacher.IfTeacher)
                Label_iftch.Text = "是";
            else Label_iftch.Text = "否";
            if (myTeacher.IfClassTeacher)
                Label_ifctch.Text = "是";
            else Label_ifctch.Text = "否";

        }

        protected void ImageButton_Edit_Click(object sender, ImageClickEventArgs e)
        {
            //拿Account中得currentRole
            Account myAccount = (Account)Session["Account"];
            Staff myStaff = new Staff();
            switch (myAccount.RoleCurrent)
            {
                case 'a': myStaff = (Admin)Session["Admin"]; break;
                case 'c': myStaff = (ClassTeacher)Session["ClassTeacher"]; break;
                case 't': myStaff = (Teacher)Session["Teacher"]; break;
                default: Response.Redirect("~/"); break;
            }

            Staff myTeacher = myStaff;
            myTeacher.TeacherName = TextBox_tchname.Text.ToString();
            myTeacher.TeacherGender = DropDownList_gender.SelectedItem.Text.ToString();
            myTeacher.TeacherOffice = TextBox_tchoffice.Text.ToString();
            myTeacher.TeacherOfficeTel = TextBox_tchofficetel.Text.ToString();
            myTeacher.TeacherMobile = TextBox_tchmobile.Text.ToString();
            myTeacher.TeacherMail = TextBox_tchmail.Text.ToString();
            myTeacher.TeacherAward = TextBox_tchaward.Text.ToString();
            myTeacher.TeacherField = TextBox_tchfield.Text.ToString();
            myTeacher.TeacherTitle = TextBox_tchtitle.Text.ToString();
           
            
            //进行修改
            string str = myTeacher.PersonalInfomationEdit();
            
            //判断操作是否成功
            if (str.CompareTo(Resources.ErrorMessage.OK) == 0)
                Response.Redirect("TeaInformation.aspx");
            else Label_result.Text = Resources.ErrorMessage.DBOptError;
        }

        protected void ImageButton_Cancel_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("TeaInformation.aspx");
        }
    }
}
